package com.xd.cloud.dao.device;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.xd.cloud.dao.BaseDao;
import com.xd.cloud.dao.Page;
import com.xd.cloud.entity.device.Device;

/**   
 * 功能描述：设备信息Dao
 * @author: wangshanshan   
 * @date: 2017年12月11日 上午10:17:47 
 */
@Repository
public class DeviceDao extends BaseDao<Device> {
	
	public Page getAllDevice(int pageNo, int pageSize){
		String sql = "select d.id,d.device_id,d.serial_id,d.device_type,dic.value,d.brand,d.model,d.install,d.install_time,d.company_id,c.name,v.vehid from tb_device d " + 
				"left join sys_dic dic on d.device_type = dic.key and dic.type = 'device_type' " + 
				"left join sys_company c on d.company_id = c.id "+
				"left join tb_vehicle v on d.device_id = v.devicecode order by d.id desc";
		return pagedSqlQuery(sql, pageNo, pageSize);
	}
	
	public Device getDeviceById(int id) {
		String hql = "from Device where id = ?";
		return get(hql, new Object[]{id});
	}
	
	public Device getDeviceByDeviceId(String device_id) {
		String hql = "from Device where device_id = ?";
		return get(hql, new Object[]{device_id});
	}
	
	public Object getDeviceObjectById(int id) {
		String sql = "select d.id,d.device_id,d.serial_id,d.device_type,d.brand,d.model,d.install,d.install_time,d.factory_type,\r\n" + 
				"d.software_ver,d.hardware_ver,d.product_manufacturer,d.remark,d.company_id,c.name from tb_device d\r\n" + 
				"left join sys_company c on d.company_id = c.id where d.id = ? order by d.id desc";
		return getsqlResult(sql, new Object[]{id});
	}
	
	
	//根据是否安装来查询所有设备
	public List<Device> getDeviceList(int install) {
		String hql = "from Device where install=?";
		return find(hql, new Object[]{install});
	}
	
	//根据是否安装来查询所有设备
	public Device getDeviceBydeviceid(String deviceId) {
		String hql = "from Device where device_id=?";
		return get(hql, new Object[]{deviceId});
	}
}
